import { login } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'
const state = {
  token: getToken() || null

}
const mutations = {
  setToken(state, newToken) {
    state.token = newToken
    // 保存token
    setToken(newToken)
  }
}

const actions = {
  async login(context, payload) {
    console.log('login', context, payload)
    const result = await login(payload)
    console.log('action login', result)
    // const token = result.data
    // 传token 假设已经拿到了token的值
    const token = 123456
    context.commit('setToken', token)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
